package tienda.zapateria.siszap.da;

import java.sql.Connection;
import tienda.zapateria.siszap.be.BEDetalleCarrito;
import java.util.ArrayList;
import org.rx.cr.dao.DAOAbstract;

public class DADetalleCarrito extends DAOAbstract<BEDetalleCarrito> {

    public DADetalleCarrito(Connection c) {
        setConnection(c);
    }

    @Override
    public int registrar(BEDetalleCarrito be) throws Exception {
        try {
            setStoreProcedure("zapateria.sp_ins_detallecarrito");
            setParameterInt(be.getCarritoid());
            setParameterInt(be.getArticuloid());
            setParameterInt(be.getCantidad());
            return Integer.parseInt(commit().toString());
        } catch (Exception e) {
            return rollback(e);
        }
    }

    @Override
    public int actualizarRegistro(BEDetalleCarrito be) throws Exception {
        try {
            setStoreProcedure("zapateria.sp_upd_detallecarrito");
            setParameterInt(be.getDetallecarritoid());
            setParameterInt(be.getCarritoid());
            setParameterInt(be.getArticuloid());
            setParameterInt(be.getCantidad());

            return Integer.parseInt(commit().toString());
        } catch (Exception e) {
            return rollback(e);
        }
    }

    @Override
    public int eliminarRegistro(BEDetalleCarrito be) throws Exception {
        try {
            setStoreProcedure("zapateria.sp_del_detallecarrito");
            setParameterInt(be.getDetallecarritoid());
            return Integer.parseInt(commit().toString());
        } catch (Exception e) {
            return rollback(e);
        }
    }

    @Override
    public ArrayList<BEDetalleCarrito> buscarReferencia(String string) throws Exception {
        try {
            clear();
            setStoreProcedure("zapateria.sp_sel_detallecarrito");
            setParameterString(string);
            commitc();
            while (existResult()) {
                BEDetalleCarrito be = new BEDetalleCarrito();
                be.setDetallecarritoid(getDataInt(1));
                be.setCarritoid(getDataInt(2));
                be.setArticuloid(getDataInt(3));
                be.setCantidad(getDataInt(4));

                add(be);
            }
            return getLista();
        } catch (Exception e) {
            rollback(e);
            return null;
        }
    }

    @Override
    public ArrayList<BEDetalleCarrito> listar() throws Exception {
        try {
            clear();
            setStoreProcedure("zapateria.sp_sel_detallecarrito");
            setParameterString("");
            commitc();
            while (existResult()) {
                BEDetalleCarrito be = new BEDetalleCarrito();
                be.setDetallecarritoid(getDataInt(1));
                be.setCarritoid(getDataInt(2));
                be.setArticuloid(getDataInt(3));
                be.setCantidad(4);
                add(be);
            }
            return getLista();
        } catch (Exception e) {
            rollback(e);
            return null;
        }
    }

    @Override
    public BEDetalleCarrito buscar(int i) throws Exception {
        try {
            BEDetalleCarrito be = null;
            clear();
            setStoreProcedure("zapateria.sp_sel_detallecarrito_id");
            setParameterInt(i);
            commitc();
            while (existResult()) {
                be = new BEDetalleCarrito();
                be.setDetallecarritoid(getDataInt(1));
                be.setCarritoid(getDataInt(2));
                be.setArticuloid(getDataInt(3));
                be.setCantidad(getDataInt(4));

            }
            return be;
        } catch (Exception e) {
            rollback(e);
            return null;
        }
    }

}
